2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCER_PAINTELEMENTUNDOABLEACTION_JUCEHEADER__
27 #define __JUCER_PAINTELEMENTUNDOABLEACTION_JUCEHEADER__
29 #include "../../ui/jucer_JucerDocumentHolder.h"
30 #include "jucer_PaintElementGroup.h"
33 //==============================================================================
36 template <class ElementType
>
37 class PaintElementUndoableAction
: public UndoableAction
40 PaintElementUndoableAction (ElementType
* const element
)
41 : routine (*element
->getOwner()),
42 elementIndex (element
->getOwner()->indexOfElement (element
))
44 jassert (element
!= 0);
47 findGroupIndices (element
->getOwner(), element
);
49 jassert (elementIndex
>= 0);
52 ~PaintElementUndoableAction()
56 ElementType
* getElement() const
58 if (containerGroups
.size() > 0)
60 PaintElementGroup
* group
= 0;
61 group
= dynamic_cast <PaintElementGroup
*> (routine
.getElement (containerGroups
.getFirst()));
66 for (int i
= 1; i
< containerGroups
.size(); ++i
)
68 group
= dynamic_cast <PaintElementGroup
*> (group
->getElement (containerGroups
.getUnchecked(i
)));
74 ElementType
* const e
= dynamic_cast <ElementType
*> (group
->getElement (elementIndex
));
80 ElementType
* const e
= dynamic_cast <ElementType
*> (routine
.getElement (elementIndex
));
86 int getSizeInUnits() { return 2; }
89 PaintRoutine
& routine
;
91 Array
<int> containerGroups
;
95 jassert (routine
.getDocument() != 0);
96 routine
.getDocument()->changed();
99 void showCorrectTab() const
101 JucerDocumentHolder
* const docHolder
= JucerDocumentHolder::getActiveDocumentHolder();
104 docHolder
->showGraphics (&routine
);
106 if (routine
.getSelectedElements().getNumSelected() == 0)
108 ElementType
* const e
= dynamic_cast <ElementType
*> (routine
.getElement (elementIndex
));
111 routine
.getSelectedElements().selectOnly (e
);
116 void findGroupIndices (PaintRoutine
* const routine
, PaintElement
* const element
)
118 for (int i
= routine
->getNumElements(); --i
>= 0;)
120 PaintElementGroup
* const pg
= dynamic_cast <PaintElementGroup
*> (routine
->getElement (i
));
122 if (pg
!= 0 && pg
->containsElement (element
))
124 containerGroups
.add (i
);
125 findGroupIndices (pg
, element
);
130 void findGroupIndices (PaintElementGroup
* const group
, PaintElement
* const element
)
132 elementIndex
= group
->indexOfElement (element
);
133 if (elementIndex
< 0)
135 for (int i
= group
->getNumElements(); --i
>= 0;)
137 PaintElementGroup
* pg
= dynamic_cast <PaintElementGroup
*> (group
->getElement (i
));
139 if (pg
!= 0 && pg
->containsElement (element
))
141 containerGroups
.add (i
);
142 findGroupIndices (pg
, element
);
148 PaintElementUndoableAction (const PaintElementUndoableAction
&);
149 PaintElementUndoableAction
& operator= (const PaintElementUndoableAction
&);
154 #endif // __JUCER_PAINTELEMENTUNDOABLEACTION_JUCEHEADER__